# -*- coding: utf-8 -*-
#
# @Time    ： 2023/2/16  16:43
# @Auther  ： 徐良
# File     :  custDateParts.py

from PySide6 import QtWidgets
from PySide6.QtWidgets import QDateEdit, QTimeEdit, QDateTimeEdit
from PySide6.QtCore import Qt, QDate


class DateEditBase(QDateEdit):

    def __init__(self, parent=None):
        super(DateEditBase, self).__init__(parent)
        self.setCalendarPopup(True)
        self.ROB = 0

    def setROB(self, value):
        if self.ROB != value:
            self.ROB = value
            self.setStyleSheet("color: red;") if self.ROB == 1 else self.setStyleSheet("color: rgb(37, 43, 65);")


class CustDateEdit(DateEditBase):
    """
    自定义日期控件
    """

    def __init__(self, parent=None):
        super(CustDateEdit, self).__init__(parent)
        self.setDisplayFormat("yyyy-MM-dd")
        self.setDate(QDate.currentDate())

    def keyPressEvent(self, e):
        """
        回车事件
        :param e:
        """
        QtWidgets.QDateEdit.keyPressEvent(self, e)

        if e.key() == Qt.Key_Enter:
            self.focusNextChild()

class TimeEditBase(QTimeEdit):
    """
    自定义日期控件基础
    """

    def __init__(self, parent=None):
        super(TimeEditBase, self).__init__(parent)
        self.ROB = 0

    def setROB(self, value):
        if self.ROB != value:
            self.ROB = value
            self.setStyleSheet("color: red;") if self.ROB == 1 else self.setStyleSheet("color: rgb(37, 43, 65);")





class DateTimeEditBase(QDateTimeEdit):

    def __init__(self, parent=None):
        super(DateTimeEditBase, self).__init__(parent)
        self.ROB = 0

    def setROB(self, value):
        if self.ROB != value:
            self.ROB = value
            self.setStyleSheet("color: red;") if self.ROB == 1 else self.setStyleSheet("color: rgb(37, 43, 65);")





class CustTimeEdit(TimeEditBase):

    def __init__(self, parent=None):
        super(CustTimeEdit, self).__init__(parent)
        self.setDisplayFormat("hh:mm")

    def keyPressEvent(self, e):
        QtWidgets.QTimeEdit.keyPressEvent(self, e)
        if e.key() == Qt.Key_Enter:
            self.focusNextChild()


class CustDateTimeEdit(DateTimeEditBase):

    def __init__(self, parent=None):
        super(CustDateTimeEdit, self).__init__(parent)
        self.setDisplayFormat("yyyy-MM-dd hh:mm:ss")
        self.setDate(QDate.currentDate())

    def keyPressEvent(self, e):
        QtWidgets.QDateTimeEdit.keyPressEvent(self, e)

        if e.key() == Qt.Key_Enter:
            self.focusNextChild()

